@extends ('shop-backend::store.layout')

@section ('title','城市列表')

@section ('breadcrumbs')
    <h2>城市列表</h2>

    <ol class="breadcrumb">
        <li><i class="fa fa-dashboard"></i> 首页</li>
        <li>{!! link_to_route('admin.shop.list.store', '门店') !!}</li>
        <li class="active">城市列表</li>
    </ol>
@stop

@section('content')
    <div class="ibox float-e-margins">
        <div class="ibox-content" style="display: block;">
            <div class="row">
                <div class="col-md-6">
                    <div class="btn-group">
                        <a class="btn btn-primary " href="{{route('admin.shop.list.city.curd')}}">添加城市</a>
                    </div>
                    <form method="get" action="">
                        <div class="input-group search_text">
                            <input type="text" name="name" placeholder="城市名称" value="{{!empty(request('name'))?request('name'):''}}" class=" form-control">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-primary">查找</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
            <div style="clear: both;"></div>
            <div class="hr-line-dashed"></div>
            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>城市名称</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    @if (!empty($data))
                        @foreach ($data as $v)
                            <tr>
                        <td>{!! $v->name !!}</td>
                        <td>
                            <a href="{!!route('admin.shop.list.city.curd', ['id' => $v->id])!!}" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="" data-original-title="编辑"></i></a>
                            <a class="btn btn-xs btn-danger" style="cursor:pointer;" onclick="del_city({!!$v -> id!!});"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="" data-original-title="删除"></i></a>
                        </td>
                    </tr>
                        @endforeach
                    @endif
                    <meta name="csrf-token" content="{{ csrf_token() }}">
                </tbody>
            </table>
            {!! $data->render() !!}
            <div class="pull-right">
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
@stop
@section('after-scripts-end')
    <script>
        function del_city(id) {
            if (confirm('确定删除此项？会影响门店列表功能')) {
                $.ajax({
                    type: 'POST',
                    url: "{!!route('store.ajax.del')!!}",
                    data: {'id': id, 'type': 'city'},
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        if (200 == data.code) {
                            swal({
                                title: "删除成功！",
                                text: "",
                                type: "success"
                            }, function() {
                                location = '{{route('admin.shop.list.city')}}';
                            });
                        } else {
                            swal("删除失败！", data.message, 'warning');
                        }
                    }
                });
            }
        }
</script>
@stop